package com.mzj.saas.mservice.property.controller;

import com.mzj.saas.annotation.RepeatSubmit;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.property.entity.EstateRepairsEvaluation;
import com.mzj.saas.mservice.property.service.EstateRepairsRecordService;
import com.mzj.saas.mservice.property.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 报事报修
 *
 * @author hikari
 * @since 2021-05-15
 */
@RestController
@RequestMapping("/property/estateRepairsRecord")
public class EstateRepairsRecordController {
    @Autowired
    private EstateRepairsRecordService estateRepairsRecordService;

    /**
     * 报修记录列表
     *
     * @param accessToken
     * @param houseId 房产id
     * @param communityId 小区
     * @param buildId 楼宇
     * @param unitId 单元
     * @param roomNumber 房号
     * @param floor 楼层
     * @param operatorName 发起人姓名
     * @param operatorMobile 发起人电话
     * @param startTime 发起时间
     * @param endTime 结束时间
     * @param type 报修服务 1=私有 2=公共区域
     * @param status
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResultBean<EstateRepairsRecordApiData<EstateRepairsRecordVO>> list(@RequestHeader String accessToken,
                                                                              @RequestParam(required = false) String houseId,
                                                                              @RequestParam(required = false) String communityId,
                                                                              @RequestParam(required = false) Long buildId,
                                                                              @RequestParam(required = false) Long unitId,
                                                                              @RequestParam(required = false) String roomNumber,
                                                                              @RequestParam(required = false) Integer floor,
                                                                              @RequestParam(required = false) String operatorName,
                                                                              @RequestParam(required = false) String operatorMobile,
                                                                              @RequestParam(required = false) String startTime,
                                                                              @RequestParam(required = false) String endTime,
                                                                              @RequestParam(required = false) Integer type,
                                                                              @RequestParam(required = false) Integer status,
                                                                              @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                              @RequestParam(defaultValue = "5") Integer pageSize) {
        return estateRepairsRecordService.list(accessToken, houseId, communityId, buildId, unitId, roomNumber, floor,
                operatorName, operatorMobile, startTime, endTime, type, status, pageNumber, pageSize);
    }


    /**
     * 报修记录详情
     */
    @GetMapping("/getInfo/{id}")
    public ResultBean<EstateRepairsRecordVO> getInfo(@RequestHeader String accessToken, @PathVariable("id") Long id) {
        return estateRepairsRecordService.getInfo(accessToken, id);
    }

    /**
     * 查询用户可报修房产
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/repairsHouse")
    public ResultBean<List<RepairsHouse>> findRepairsHouse(@RequestHeader String accessToken) {
        return estateRepairsRecordService.findRepairHouse(accessToken);
    }

    /**
     * 房屋信息搜索
     *
     * @param accessToken
     * @param residenceCommunityId
     * @param buildingNum
     * @param unit
     * @param roomNumber
     * @return
     */
    @GetMapping("/nonPersonalProperty")
    public ResultBean<List<RepairsHouse>> findNonPersonalProperty(@RequestHeader String accessToken,
                                                                  @RequestParam(required = false) String residenceCommunityId,
                                                                  @RequestParam(required = false) Long buildingNum, @RequestParam(required = false) Long unit,
                                                                  @RequestParam(required = false) String roomNumber) {
        return estateRepairsRecordService.findNonPersonalProperty(accessToken, residenceCommunityId, buildingNum, unit,
                roomNumber);
    }

    /**
     * 上报报修
     *
     * @param accessToken
     * @param estateRepairsRecordVO
     * @return
     */
    @PostMapping
    @RepeatSubmit
    public ResultBean<EstateRepairsRecordVO> save(@RequestHeader String accessToken,
                                                  @Valid @RequestBody EstateRepairsRecordVO estateRepairsRecordVO) {
        return estateRepairsRecordService.save(accessToken, estateRepairsRecordVO);
    }

    /**
     * 分派
     *
     * @param accessToken
     * @param id
     * @param serviceUserId
     * @return
     */
    @PostMapping("/assign/{id}")
    @RepeatSubmit
    public ResultBean<EstateRepairsRecordVO> assign(@RequestHeader String accessToken, @PathVariable Long id,
                                                    @RequestParam String serviceUserId) {
        return estateRepairsRecordService.assign(accessToken, id, serviceUserId);
    }

    /**
     * 维修
     *
     * @param accessToken
     * @param id
     * @return
     */
    @PostMapping("/fix/{id}")
    @RepeatSubmit
    public ResultBean<Object> fix(@RequestHeader String accessToken, @PathVariable Long id) {
        return estateRepairsRecordService.fix(accessToken, id);
    }

    /**
     * 维修完成
     *
     * @param accessToken
     * @param id
     * @return
     */
    @RepeatSubmit
    @GetMapping("/fixComplete/{id}")
    public ResultBean<Object> fixComplete(@RequestHeader String accessToken,
                                          @PathVariable Long id) {
        return estateRepairsRecordService.fixComplete(accessToken, id);
    }

    /**
     * 查看收费项目详情
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/{id}/cost")
    public ResultBean<List<EstateRepairsCostDetailVO>> getCosts(@RequestHeader String accessToken,
                                                                @PathVariable Long id) {
        return estateRepairsRecordService.getCosts(accessToken, id);
    }

    /**
     * 确定收费项目
     *
     * @param accessToken
     * @param id
     * @param estateRepairsCostVOList
     * @return
     */
    @PostMapping("/{id}/cost")
    @RepeatSubmit
    public ResultBean<List<EstateRepairsCostDetailVO>> addCosts(@RequestHeader String accessToken,
                                                                @PathVariable Long id, @RequestBody List<EstateRepairsCostVO> estateRepairsCostVOList) {
        return estateRepairsRecordService.addCosts(accessToken, id, estateRepairsCostVOList);
    }

    /**
     * 查看评论
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/{id}/evaluation")
    public ResultBean<EstateRepairsEvaluationVO> getEvaluation(@RequestHeader String accessToken, @PathVariable Long id) {
        return estateRepairsRecordService.getEvaluation(accessToken, id);
    }

    /**
     * 评论
     *
     * @param accessToken
     * @param id
     * @param vo
     * @return
     */
    @PostMapping("/{id}/evaluation")
    @RepeatSubmit
    public ResultBean<EstateRepairsEvaluation> addEvaluation(@RequestHeader String accessToken, @PathVariable Long id,
                                                             @RequestBody EstateRepairsEvaluationVO vo) {
        return estateRepairsRecordService.addEvaluation(accessToken, vo);
    }

    /**
     * 撤销报事报修
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @RepeatSubmit
    public ResultBean<Object> delete(@RequestHeader String accessToken, @PathVariable Long id) {
        return estateRepairsRecordService.delete(accessToken, id);
    }

    /**
     * 报修详情
     *
     * @param accessToken
     * @param id
     * @return
     */
    @GetMapping("/find/{id}")
    public ResultBean<Object> find(@RequestHeader String accessToken, @PathVariable Long id) {
        return estateRepairsRecordService.find(accessToken, id);
    }

}
